<template>
	<view>
		<u-sticky bgColor="#a3d8f5">
			<view class="mainpadding" :style="{paddingTop:menutop+'rpx'}">
				<view class="flexleft">
					<image src="@/static/image/system/hsz.png" class="hszclass" mode=""></image>
					<view class="xiaobai fonweight" style="font-size: 35rpx;">红十字基金会“孤寡老人大病救助基金”</view>
				</view>
				<view class="margin_top flexbetween">
					<view class="topliclass"></view>
					<view class="xiaobai fonweight sanshier" style="font-size: 32rpx;">{{titletype==1?'公益活动':'惠民义诊'}}</view>
					<image src="@/static/image/system/list.png" mode="" class="topliclass" @tap="toplistfn"></image>
				</view>
			</view>
		</u-sticky>
		<view class="mainpadding">
			<view class="mainpadding ffffff radius">
				<view class="flexbetween">
					<view class="flexcolumn"   v-if="!isSH" @click="jumpurl('/pages/zhengce/zhengcejd')">
						<image src="@/static/image/system/zcjd.jpg" style="width: 100rpx;height: 100rpx;border-radius: 50%;" mode=""></image>
						<view class="xiaohei ershiba margin_top1">救助解读</view>
					</view>
					<view class="flexcolumn" v-if="!isSH" @click="changetype(1)">
						<image src="@/static/image/system/gyhd.png" style="width: 100rpx;height: 100rpx;border-radius: 50%;" mode=""></image>
						<view class="xiaohei ershiba margin_top1">公益活动</view>
					</view>
					<view class="flexcolumn" v-if="!isSH" @click="changetype(2)">
						<image src="@/static/image/system/hmyz.png" style="width: 100rpx;height: 100rpx;border-radius: 50%;" mode=""></image>
						<view class="xiaohei ershiba margin_top1">惠民义诊</view>
					</view>
					<view class="flexcolumn"  @click="jumpurl('/pages/zhengce/gongyibm')">
						<image src="@/static/image/system/gybm.jpg" style="width: 100rpx;height: 100rpx;border-radius: 50%;" mode=""></image>
						<view class="xiaohei ershiba margin_top1">公益报名</view>
					</view>
				</view>
			</view>
			<view class="ffffff margin_top" style="padding-bottom: 10rpx;" v-for="item in list.data" :key="item.id" @click="jumpdetail(item.id)">
				<image :src="item.image_text" style="width: 100%;height: 300rpx;border-radius: 20rpx 20rpx 0 0;" mode=""></image>
				<view class="ershiba xiaohei margin_top1 bold xiankuan margin_left3">{{item.name}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// #ifdef H5
				menutop: 80,
				// #endif
				// #ifdef MP-WEIXIN
				menutop: 0,
				// #endif	
				titletype:1,//活动，2义诊
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				isSH:true
			}
		},
		onShareAppMessage: function(options) {
			return {
				title: '红十字基金会“孤寡老人大病救助基金”',
				imageUrl: '',
				path: '/pages/index/index'
			}
		},
		onShareTimeline: function() {
			return {
				title: '红十字基金会“孤寡老人大病救助基金”',
				imageUrl: '',
				path: '/pages/index/index'
			}
		},
		onLoad() {
			// #ifdef MP-WEIXIN
			this.menutop = uni.getMenuButtonBoundingClientRect().top * 2
			// #endif
			this.init()
			this.getshsystem()
		},
		methods: {
			getshsystem() {
				let _this = this
				let system = uni.getSystemInfoSync()
				let version_code = system.appVersionCode
				httpRequest.request('/api/index/checkApply', 'GET', {
					platform:"wechat",
					version_code
				}).then(res => {
					console.log(version_code, res);
					this.isSH = res.data
				})
			},
			jumpurl(url){
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				uni.navigateTo({
					url
				})
			},
			jumpdetail(id){
				uni.navigateTo({
					url:'/pages/zhengce/huodongxq?id='+id+"&type="+this.titletype
				})
			},
			init(isPage, page) {
				let _this = this
				let url = "/api/index/gyhdIndex"
				if(this.titletype==2){
					url = "/api/index/hmyzIndex"
				}
				httpRequest.request(url, 'GET', {
					page: page || 1,
					limit: 12,
				}).then(res => {
					uni.stopPullDownRefresh()
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			changetype(val){
				if(this.titletype == val){
					return false
				}
				this.titletype = val
				this.page = 1
				this.list = {
					data:[]
				}
				this.init()
			}
		}
	}
</script>

<style>

</style>
